home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / time.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  1KB  |  53 lines

  1. /* time.c : return the elapsed seconds since midnight Jan 1 1970 GMT */
  2. /* written by Eric R. Smith and placed in the public domain */
  3.  
  4. #include <time.h>
  5. #include <osbind.h>
  6. #include "lib.h"
  7.  
  8. static struct tm this_tm;
  9. int _dst;
  10.  
  11. /* unixtime: convert a DOS time/date pair into a unix time */
  12. /* in case people were wondering about whether or not DST is applicable
  13.  * right now, we set the external variable _dst to the value
  14.  * returned from mktime
  15.  */
  16.  
  17. time_t 
  18. _unixtime(dostime, dosdate)
  19.     unsigned dostime, dosdate;
  20. {
  21.     time_t t;
  22.     struct tm *stm = &this_tm;
  23.  
  24.     stm->tm_sec = (dostime & 31) << 1;
  25.     stm->tm_min = (dostime >> 5) & 63;
  26.     stm->tm_hour = (dostime >> 11) & 31;
  27.     stm->tm_mday = dosdate & 31;
  28.     stm->tm_mon = ((dosdate >> 5) & 15) - 1;
  29.     stm->tm_year = 80 + ((dosdate >> 9) & 255);
  30.     stm->tm_isdst = -1;    /* we don't know about DST */
  31.     stm->tm_wday = stm->tm_yday = -1; /* or about these */
  32.  
  33. /* mktime expects a local time, which is what we're giving it */
  34.     t = mktime(stm);
  35.  
  36.     _dst = (stm->tm_isdst == 1) ? 1 : 0;
  37.     return t;
  38. }
  39.  
  40. time_t time(t)
  41.     time_t *t;
  42. {
  43.     unsigned dostime, dosdate;
  44.     time_t    made;
  45.  
  46.     dostime = Tgettime();
  47.     dosdate = Tgetdate();
  48.     made = _unixtime(dostime, dosdate);
  49.     if (t)
  50.         *t = made;
  51.     return made;
  52. }
  53.